function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var e = Object.assign || function(t) {
    for (var e = 1; e < arguments.length; e++) {
        var i = arguments[e];
        for (var a in i) Object.prototype.hasOwnProperty.call(i, a) && (t[a] = i[a]);
    }
    return t;
}, i = t(require("../../../utils/util")), a = t(require("../../../utils/config")), n = t(require("../../../utils/api2")), s = require("../../../components/navigation-bar/mixin"), o = t(require("../../../components/editor/editor")), d = t(require("../../../components/editor-content-view/editor-content-view")), r = getApp();

Page({
    data: {
        app: r.globalData.app,
        $$editor: {},
        site: {
            content: []
        },
        mode: "view",
        isLoading: !0,
        saving: !1,
        isExist: !0,
        saveButtonShown: !0,
        shoppingcartInitData: {}
    },
    handleRedirect: function(t) {
        t.scene && (wx.showLoading({
            title: "正在跳转",
            mask: !0
        }), n.default.v4.weapp.getdatafromscene({
            data: {
                scene: t.scene,
                app: r.globalData.app
            },
            complete: wx.hideLoading
        }).then(function(t) {
            var n = t.params, s = t.type, o = void 0;
            o = "payment" === s ? "/pages/common/payment/payment?sid=" + n.sid + "&appid=" + n.appid : 0 == +s ? "/pages/website/index/index?sid=" + n.sid : i.default.createModelUrl(a.default.model, e({}, n, {
                modid: s
            })), wx.navigateTo({
                url: o
            });
        }));
    },
    onLoad: function(t) {
        var e = this;
        this.handleRedirect(t), "thirdparty" === r.globalData.app && (t = {
            sid: r.globalData.sid
        }), this.setData({
            "site.sid": t.sid
        }), s.navigationMixIn.addTo(this), this.loadSiteInfo(t), this.addPlugins(t), this.loadSiteHomeContent(t).then(function() {
            e.$emit("update:viewlist", {
                mode: "view"
            });
        }), this.$addListener("update.editorcontent", function() {
            var t = e.data.site.sid;
            e.loadSiteHomeContent({
                sid: t
            });
        });
    },
    onShow: function() {
        var t = Date.now();
        this.setData({
            _radarStartTime: t
        }), i.default.deleteOriginSiteData();
    },
    addPlugins: function(t) {
        var e = this;
        this.editor = new o.default(this, {
            sid: t.sid
        }), Object.assign(this.editor, {
            onFocus: function() {
                return e.setData({
                    saveButtonShown: !1
                });
            },
            onBlur: function() {
                return e.setData({
                    saveButtonShown: !0
                });
            }
        }), this.manager = new d.default(this, {
            scope: "site"
        }), this.setData({
            sharePluginData: {
                sid: t.sid,
                navid: "",
                catid: "",
                cid: "",
                modid: 0,
                op: "link"
            }
        });
    },
    loadSiteInfo: function(t) {
        var e = this, a = t.sid, s = t.navid;
        return n.default.site.site.view({
            data: {
                sid: a
            }
        }).then(function(t) {
            var a = i.default.formatSidebarNavUrl(t.navlist, s);
            e.initNavigation(t, a), e.setData({
                "site.tel": t.tel,
                "site.mchid": t.mchid
            }), i.default.setTheme(t.style), e.$emit("update.editorTypes", {
                version: t.version
            });
        }).catch(function(t) {
            -100005 === t.code && e.setData({
                isExist: !1
            });
        });
    },
    loadSiteHomeContent: function(t) {
        var e = this;
        return n.default.site.site.viewhomepage({
            data: t
        }).then(function(t) {
            var i = t.content, a = t.isedit, n = t.isfocus;
            e.setData({
                "site.content": i,
                "site.isedit": a,
                "site.isfocus": n,
                "site.app": e.data.app,
                isLoading: !1
            });
        }, function(t) {
            -100005 === t.code ? e.setData({
                isExist: !1
            }) : i.default.qAlert(t.message, "加载内容失败"), e.setData({
                isLoading: !1
            });
        });
    },
    editContent: function() {
        var t = this.data.site.content;
        this.editor.setData(t || []), this.setData({
            mode: "edit"
        });
    },
    saveHomeContent: function() {
        var t = this;
        this.setData({
            saving: !0
        });
        var e = {
            sid: this.data.site.sid,
            cid: this.data.site.cid,
            content: this.editor.getData()
        };
        n.default.site.home.save({
            data: e,
            desc: "保存",
            complete: function() {
                return t.setData({
                    saving: !1
                });
            }
        }).then(function() {
            t.setData({
                "site.content": e.content,
                mode: "view",
                swiper: []
            });
            var i = t.data.$$editor.deleteLinkSource;
            t.$$editorDeleteLinkSource(i);
        });
    },
    cancelEdit: function() {
        var t = this;
        wx.showModal({
            title: "操作提示",
            content: "确定放弃本次修改吗？点击确定后，将不保存修改内容",
            cancelText: "再想想",
            success: function(e) {
                if (e.confirm) {
                    var i = t.data.site.content;
                    t.editor.setData(i || []), t.setData({
                        mode: "view"
                    });
                }
            }
        });
    },
    updateEditStatus: function() {
        var t = this.data, e = t.site.content, i = void 0 === e ? [] : e, a = t.$$editor.sections;
        i.length || a.length || this.$$editorAddSection({
            type: "text",
            data: {
                content: ""
            }
        }, 0), this.setData({
            mode: "edit"
        });
    },
    updateIndexFocus: function(t) {
        this.$emit("site:focus", t.detail);
    },
    redirectToMembers: function() {
        var t = this.data.sidebar.site.sid;
        this.$route("/pages/profile-entry/members/members?sid=" + t);
    },
    onHide: function() {
        var t = this.data, e = t._radarStartTime, a = t.site.sid, n = Date.now(), s = Math.round((n - e) / 1e3);
        i.default.pushRadarNews("viewsitev2", a, {
            sid: a
        }, s > 100 ? 99 : s);
    },
    onUnload: function() {
        var t = this.data, e = t._radarStartTime, a = t.site.sid, n = Date.now(), s = Math.round((n - e) / 1e3);
        i.default.pushRadarNews("viewsitev2", a, {
            sid: a
        }, s > 100 ? 99 : s);
    },
    onShareAppMessage: function() {
        this.setData({
            isSharePluginShow: !1
        });
        var t = r.globalData.tokens, e = this.data.sidebar.site, a = e.sid, n = e.name;
        return i.default.saveShareRecord(a), {
            title: "欢迎访问“" + n + "”",
            path: "/pages/website/index/index?sid=" + a + "&fromuid=" + t.uid
        };
    }
});